#include <reg51.h>

unsigned char LED[] = {0x3f, 0x06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0x07, 0x7f, 0x6f};

unsigned char status = 0;

void serverConfig();

void buttonInterrupt();

void runServer();

void delay1ms();

void main(void) {
    serverConfig();
    runServer();
}

void serverConfig() {
    EA = 1;
    EX0 = 1;
    IT0 = 1;
    P2 = 0xff;
}

void runServer() {
    while (1) {
        P1 = LED[status % 10];
        P2 = ~(0x07 << (status % 3));
        delay1ms();
    }
}

void buttonInterrupt() interrupt 0{
    status++;
    if (status == 1000) status = 0;
}

void delay1ms() {
    TMOD = 0X16;
    TH1 = 0xfc;
    TL1 = 0x18;
    TR1 = 1;
    while (!TF1); // 等带中断溢出
    P1 = 0x00;    // 清除数字，防止显示错误
    TF1 = 0;
}